﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Configuration;
using MPSE.Portal2;

public partial class Login : System.Web.UI.Page
{

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoginTextBox.Text = "@mp.se.gov.br";
            LoginTextBox.Focus();
        }
    }
    #endregion

    #region LoginButton_Click
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        try
        {
            int cdAplicacao = Convert.ToInt32(ConfigurationManager.AppSettings["COD_APLICACAO"].ToString());
            PortalMPSE.Login(this, cdAplicacao, LoginTextBox.Text, SenhaTextbox.Text);
            UsuarioAplicacao usuario = (UsuarioAplicacao)Session["usuario"];

            FormsAuthentication.RedirectFromLoginPage(usuario.CdGrupo, false);
        }
        catch (Exception ex)
        {
            MensagemLabel.Text = ex.Message.ToString();
        }
    }
    #endregion

    #region LembrarButton_Click
    protected void LembrarButton_Click(object sender, EventArgs e)
    {
        MensagemLabel.Text = "";
        try
        {
            string email = LoginTextBox.Text;
            PortalMPSE.EnviarEmailComSenha(email);
            MensagemLabel.Text = "Senha enviada !";
        }
        catch (Exception ex)
        {
            MensagemLabel.Text = ex.Message;
        }
    }
    #endregion

}
